home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cpptutor.arc / INTRO.TXT < prev    next >
Text File  |  1991-04-28  |  12KB  |  295 lines

  1.  
  2.  
  3.  
  4.                                                      Introduction
  5.                                                       WHAT IS C++
  6.  
  7.  
  8. THE ORIGIN OF C++
  9. _________________________________________________________________
  10.  
  11. The C programming language was developed at AT&T for the purpose
  12. of writing the operating system for the PDP-11 series of computers
  13. which ultimately became the unix operating system.  C was developed
  14. with the primary goal of operating efficiency.  Bjarne Stroustrup,
  15. also of AT&T, developed C++ in order to add object oriented
  16. constructs to the language.  Because object oriented technology was
  17. new at the time and all existing implementations of object oriented
  18. languages were very slow and inefficient, the primary goal of C++
  19. was to maintain the efficiency of C.
  20.  
  21. C++ can be viewed as a procedural language with some additional
  22. constructs, some of which are added for object oriented programming
  23. and some for improved procedural syntax.  A well written program
  24. will reflect elements of both object oriented programming style and
  25. classic procedural programming.  C++ is actually an extendible
  26. language since we can define new types in such a way that they act
  27. just like the predefined types which are part of the standard
  28. language.  C++ is designed for large scale software development.
  29.  
  30.  
  31.  
  32. HOW TO GET STARTED IN C++
  33. _________________________________________________________________
  34.  
  35. The C programming language was originally defined by the classic
  36. text authored by Kernigan and Ritchie, "The C Programming
  37. language", and was the standard used by all C programmers until a
  38. few years ago.  The ANSI standard for C was finally approved in
  39. December of 1989 and has become the official standard for
  40. programming in C.  Since the ANSI standard adds many things to the
  41. language which were not a part of the Kernigan and Ritchie
  42. definition, and changes a few, the two standards are not absolutely
  43. compatible and some of the more experienced C programmers may not
  44. have studied the newer constructs added to the language by ANSI-C.
  45.  
  46. This tutorial will assume a thorough knowledge of the C programming
  47. language and little time will be spent on the fundamental aspects
  48. of the language.  However, because we realize that many programmers
  49. have learned the dialect of C as defined by Kernigan & Ritchie,
  50. some sections will be devoted to explaining the newer additions as
  51. provided by the ANSI-C standard.  As the ANSI-C standard was in
  52. development, many of the newer constructs from C++ were included
  53. as parts of C itself, so even though C++ is a derivation and
  54. extension of C, it would be fair to say that ANSI-C has some of its
  55. roots in C++.  An example is prototyping which was developed for
  56. C++ and later added to C.
  57.  
  58.                                                          Page I-1
  59.  
  60.                                        Introduction - What is C++
  61.  
  62. The best way to learn C++ is by using it.  Almost any valid C
  63. program is also a valid C++ program, and in fact the addition of
  64. about 12 keywords is the only reason that some C programs will not
  65. compile and execute as a C++ program.  There are a few other subtle
  66. differences but we will save the discussion of them until later. 
  67. Since this is true, the best way to learn C++ is to simply add to
  68. your present knowledge and use a few new constructs as you need
  69. them for each new program.  It would be a tremendous mistake to try
  70. to use all of the new constructs in your first C++ program.  You
  71. would probably end up with an incomprehensive mixture of code that
  72. would be more inefficient than the same program written purely in
  73. C.  Add a few new constructs to your toolkit each day, and use them
  74. as needed while you gain experience with their use.
  75.  
  76. As an illustration of the portability of C to C++, all of the
  77. example programs included in the Coronado Enterprises C tutorial
  78. compile and run correctly when compiled as C++ programs with no
  79. changes.  None of the C++ programs will compile and execute
  80. correctly with any C compiler however, if for no other reason than
  81. the use of the new style of C++ comments.
  82.  
  83.  
  84.  
  85. HOW TO USE THIS TUTORIAL
  86. _________________________________________________________________
  87.  
  88. This tutorial is best used while sitting in front of your computer. 
  89. It is designed to help you gain experience with your own C++
  90. compiler in addition to teaching you the proper use of C++. 
  91. Display an example program on the monitor, using whatever text
  92. editor you usually use, and read the accompanying text which will
  93. describe each new construct introduced in the example program. 
  94. After you study the program, and understand the new constructs,
  95. compile and execute the program with your C++ compiler.
  96.  
  97. After you successfully compile and execute the example program,
  98. introduce a few errors into the program to see what kind of error
  99. messages are issued.  If you have done much programming, you will
  100. not be surprised if your compiler gives you an error message that
  101. seems to have nothing to do with the error introduced.  This is
  102. because error message analysis is a very difficult problem with any
  103. modern programming language.  The most important result of these
  104. error introduction exercises is the experience you will gain using
  105. your compiler and understanding its nuances.
  106.  
  107. In the text of the preprinted version of this tutorial, keywords,
  108. variable names, and function names will be written in bold type as
  109. an aid when you are studying the example programs.  It is
  110. impossible to include the bold words in a pure ASCII file which
  111. must be used for the shareware version, but the context will
  112. indicate which words are keywords, variable names, or function
  113. names.
  114.  
  115.  
  116.                                                          Page I-2
  117.  
  118.                                        Introduction - What is C++
  119.  
  120. The way this tutorial is written, you are not required to compile
  121. and execute every program.  At the end of each example program,
  122. listed in comments, you will find the result of execution of that
  123. program.  Some of the constructs are simple and easy for you to
  124. understand, so you may choose to ignore compilation and execution
  125. of that example program, depending upon the result of execution to
  126. give you the output.  Some students have used these results of
  127. execution to study several chapters of this tutorial on an airplane
  128. by referring to a hardcopy of the example programs.
  129.  
  130.  
  131.  
  132. DIFFERENT C++ IMPLEMENTATIONS
  133. _________________________________________________________________
  134.  
  135. There are primarily two standards for naming C++ files, one using
  136. the extension CPP and the other using the extension CXX.  All files
  137. in this tutorial use the CPP extension for naming files.  If your
  138. compiler requires the CXX extension it will be up to you to rename
  139. the files.  Even though we have tried to use the most generic form
  140. of all constructs, it is possible that some constructs will not
  141. actually compile and run with some C++ compilers.  As we find new
  142. implementations of C++, and acquire copies of them, we will compile
  143. and execute all files in an attempt to make all example programs
  144. as universal as possible.
  145.  
  146. The C++ language is very new and is changing rapidly.  The
  147. developer of the language, AT&T, has changed the formal definition
  148. several times in the last few years and the compiler writers are
  149. staying busy trying to keep up with them.  For this reason, we have
  150. included the following notes on some of the more popular compilers
  151. and how they fare with the example programs in this tutorial.
  152.  
  153. Zortech C++ version 1.07 - This compiler is based on C++ version
  154.      1.2, an earlier version defined by AT&T.  Most of the files
  155.      will compile correctly if the #include file is changed from
  156.      "iostream.h" to "stream.hpp".
  157.  
  158. Borland TURBO C++ version 1.0 - This compiler is based on C++
  159.      version 2.0.  All example programs will compile without error
  160.      using this compiler.
  161.  
  162. Zortech C++ version 2.1 - This compiler is based on C++ version
  163.      2.0.  None of the files have been tested with this compiler 
  164.      yet.
  165.  
  166.  
  167.  
  168. PRINTING OUT THE EXAMPLE PROGRAMS
  169. _________________________________________________________________
  170.  
  171. Some students prefer to work from a hardcopy of the example
  172. programs.  If you desire to print out the example programs, there
  173. is a batch file on the distribution disk to help you do this.  Make
  174.  
  175.                                                          Page I-3
  176.  
  177.                                        Introduction - What is C++
  178.  
  179. the distribution disk the default drive and type PRINTALL at the
  180. user prompt and the system will print out about 150 pages of C++
  181. programs, all of the example programs in this tutorial.
  182.  
  183. The PRINTALL batch file calls the program named LIST.EXE once for
  184. each example program on the distribution disk.  LIST.EXE was
  185. written in TURBO Pascal and compiled for your use in listing any
  186. program with line numbers and the date the program was last
  187. modified, the date and time of the file.  TURBO Pascal was used
  188. because Borland does not require a licensing fee for distributing
  189. copies of the resulting run time files.
  190.  
  191.  
  192.  
  193. PROGRAMMING EXERCISES
  194. _________________________________________________________________
  195.  
  196. There are programming exercises given at the end of each chapter
  197. to enable you to try a few of the constructs given in the chapter. 
  198. These are for your benefit and you will benefit greatly if you
  199. attempt to solve each programming problem.  If you merely read this
  200. entire tutorial, you will have a good working knowledge of C++,
  201. but you will only become a C++ programmer if you write C++
  202. programs.  The programming exercises are given as suggestions to
  203. get you started programming.
  204.  
  205. An answer for each programming exercise is given in the ANSWERS
  206. directory on the distribution disk.  The answers are all given in
  207. compilable C++ source files named in the format CHnn_m.CPP, where
  208. nn is the chapter number and m is the exercise number.  If more
  209. than one answer is required, an A, B, or C, is included following
  210. the exercise number.
  211.  
  212.  
  213.  
  214. RECOMMENDED ADDITIONAL READING
  215. _________________________________________________________________
  216.  
  217. Richard S. Wiener & Lewis J. Pinson.  "An Introduction to Object-
  218.      Oriented Programming and C++".  Addison-Wesley, 1988.  This
  219.      is the first book recommended since it covers both object
  220.      oriented programming and C++ in depth.  It is clearly written
  221.      and well organized.
  222.  
  223. Brad Cox.  "Object Oriented Programming, An Evolutionary Approach". 
  224.      Addison-Wesley, 1986.  This book is excellent for a study of
  225.      object oriented programming and what it is, but since it is
  226.      based on Objective-C, it covers nothing of the C++ language
  227.      or how to use it.
  228.  
  229. John Berry.  "The Waite Group's C++ Programming".  Howard W. Sams,
  230.      1988.  This book covers the fundamentals of the language well
  231.      and includes a significant amount of information on the
  232.      application of object oriented programming techniques.
  233.  
  234.  
  235.                                                          Page I-4
  236.  
  237.                                        Introduction - What is C++
  238.  
  239.  
  240. Bjarne Stroustrup. "The C++ Programming Language".  Addison-Wesley,
  241.      1986.  This is the definitive book on C++, but it would be
  242.      difficult for a beginner to learn the language from this book
  243.      alone.
  244.  
  245. Note that the C++ culture is in rapid change and by the time you
  246. read this, there will be additional well written texts available
  247. as aids to your learning the syntax and proper use of the C++
  248. programming language.
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.                                                          Page I-5
  295.